/**
 * @file
 * @brief Qt widget for display product info
 * @date 2020-10-23
 */
#pragma once

#include "lab.h"
#include <QWidget>

class QDoubleSpinBox;
class QLineEdit;
class QLabel;
class State;

/**
 * @class ProductView
 * @brief Qt widget for display product info
 */
class ProductView : public QWidget
{
    Q_OBJECT
public:
    /**
     * @brief Construct ProductView object
     * @param   aType   product type
     * @param   state   data source
     * @param   parent  pointer to parent widget
     */
    explicit ProductView( ProductType aType, const State & state, QWidget * parent );

public slots:
    /**
     * @brief update product data
     * @param state data source
     */
    void updateData( const State & state );

    /**
     * @brief react on inputed text
     */
    void checkText();

signals:
    /**
     * @brief Emitted when product weight was changed
     * @param   type    product type
     * @param   weight  new weight value
     */
    void weightChanged( ProductType type, double weight );

    /**
     * @brief Emitted when product value changed
     * @param   type    product type
     * @param   value   new value
     */
    void valueChanged( ProductType type, double value );

    /**
     * @brief Emitter when product factor was changed
     * @param   type    product type
     * @param   factor  new factor value
     */
    void factorChanged( ProductType type, double factor );

private:
    const ProductType type;
    QDoubleSpinBox * weight;
    QDoubleSpinBox * factor;
    QLabel * production;
    QLineEdit * value;
};
